<!DOCTYPE html>
<!-- saved from url=(0031)http://www.taffydb.com/beginner -->
<html lang="en" class="gr__taffydb_com"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
     
  <title>TaffyDB - Beginner's Guide</title>
  <meta name="description" content="">
  
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <script id="twitter-wjs" src="./index_files/widgets.js.download"></script><script type="text/javascript" async="" src="./index_files/ga.js.download"></script><script type="text/javascript" src="./index_files/XRegExp.js.download"></script> <!-- XRegExp is bundled with the final shCore.js during build -->
	<script type="text/javascript" src="./index_files/shCore.js.download"></script>
	<script type="text/javascript" src="./index_files/shBrushJScript.js.download"></script>

	<link type="text/css" rel="stylesheet" href="./index_files/shCore.css">
	<link type="text/css" rel="Stylesheet" href="./index_files/shThemeDefault.css">
	<script type="text/javascript">SyntaxHighlighter.all();</script>
    <!-- Le styles -->

    <link href="./index_files/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
      .sidebar-nav {
        padding: 9px 0;
      }
     .toolbar {
			opacity:0;
		}

	 .method {

		}
		.method td {
			border-bottom:thin solid silver;
			border-top:thin solid silver;
			vertical-align:text-top;
		}
		.method td:first-child {
			color:gray;
			background-color:#F2EDEF;
			font-size:160%;
			text-align:center;
			vertical-align:middle;
		}
		b {
			background-color:#F2EDEF;
		}
    </style>
    <link href="./index_files/bootstrap-responsive.css" rel="stylesheet">

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

    <!-- Le fav and touch icons -->
    <link rel="shortcut icon" href="http://www.taffydb.com/ico/favicon.ico">

    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="http://www.taffydb.com/ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="http://www.taffydb.com/ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="http://www.taffydb.com/ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="http://www.taffydb.com/ico/apple-touch-icon-57-precomposed.png">
  <script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-130587-11']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

  <script type="text/javascript" charset="utf-8" async="" src="./index_files/timeline.619317855a58aa2366562a395f9e40ef.js.download"></script></head>

  <body data-gr-c-s-loaded="true">

    <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">

        <div class="container-fluid">
          <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </a>
          <a class="brand" href="/">TaffyDB</a>
          <div class="pull-right">
            <a class="btn" href="https://github.com/typicaljoe/taffydb">
            taffy.js
            </a>
          </div>
          <div class="nav-collapse">
            <ul class="nav">
              <li><a href="/">Home</a></li>
              <li><a href="https://github.com/typicaljoe/taffydb/archive/master.zip">Download</a></li>
              <li class="active"><a href="/beginner.html">Beginner's Guide</a></li>
              <li><a href="/writing_queries.html">Writing Queries</a></li>
              <li><a href="/working_with_data.html">Working With Data</a></li>
              <li><a href="extentions.html">Extensions</a></li>
             </ul>
          </div><!--/.nav-collapse -->
        </div>
      </div>
    </div>

    <div class="container-fluid">
      <div class="row-fluid">
        <div class="span3">

          <div class="well sidebar-nav">
            <ul class="nav nav-list">
              <li class="nav-header">On Github</li>
              <li><a href="https://github.com/typicaljoe/taffydb">GitHub Home</a></li>

              <li><a href="https://github.com/typicaljoe/taffydb/archive/master.zip">Download</a></li>
              <li><a href="https://github.com/typicaljoe/taffydb/blob/master/taffy.js">Source Code</a></li>
                           <form id="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="ENS2E6Z99PDZN">
</form>
              <li class="nav-header">Community and Support</li>
              <li><a href="https://github.com/typicaljoe/taffydb/issues?state=open">Open Issues</a></li>

<li><a href="#" onclick="document.getElementById('paypal').submit()">Donate</a>
</li>


              <li class="nav-header">Created by</li>
           <iframe id="twitter-widget-0" scrolling="no" frameborder="0" allowtransparency="true" allowfullscreen="true" class="twitter-timeline twitter-timeline-rendered" style="position: static; visibility: visible; display: inline-block; width: 520px; height: 600px; padding: 0px; border: none; max-width: 100%; min-width: 180px; margin-top: 0px; margin-bottom: 0px; min-height: 200px;" data-widget-id="249607754170368000" title="Twitter Timeline" src="./index_files/saved_resource.html"></iframe>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>


            </ul>


          </div><!--/.well -->

        </div><!--/span-->
        <div class="span9">
          <div class="hero-unit">

               
            <h1>Beginner's Guide</h1>
            
            <p>TaffyDB is very easy to get started with. This brief turtoial will introduce you to a few of the core concepts and should be enough to get started even if you aren't already a web developer.</p>
			
			<h3>Step 1: Creating a quick sandbox</h3>
				<p>It is recmmended that you download and use your own copy of TaffyDB, but for the purposes of playing around you can use the latest version right off of GitHub. If you have never created a web page before you can simply create a text document, include the code below, and save it to your desktop as test.html.</p>
				<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;script src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"&gt;&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
	&lt;/body&gt;
				
&lt;/html&gt;</pre>
				<p>The script tag imports TaffyDB right onto the page.</p>

			<h3>Step 2: Your First DB</h3>
				<p>Let's create a DB to store some city information. You'll need another script tag and you'll be writing JavaScript.</p>
				<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;script src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"&gt;&lt;/script&gt;
		&lt;script&gt;

		var cities = TAFFY();

		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
	&lt;/body&gt;
				
&lt;/html&gt;</pre>
			<h3>Step 3: Adding records</h3>
				<p>You can add records on creation and via the .insert() method. Below we are doing both.</p>
				<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;script src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"&gt;&lt;/script&gt;
		&lt;script&gt;

		var cities = TAFFY([{name:"New York",state:"WA"},{name:"Las Vegas",state:"NV"},{name:"Boston",state:"MA"}]);
	
		cities.insert({name:"Portland",state:"OR"});

		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
	&lt;/body&gt;
				
&lt;/html&gt;</pre>
			<h3>Step 4: Your first query</h3>
				<p>Our city db is itself a function that accepts a filter object (an object that will be matched to records). Let's query for Boston. We will alert the .count() method to see our results.</p>
				<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;script src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"&gt;&lt;/script&gt;
		&lt;script&gt;

		var cities = TAFFY([{name:"New York",state:"WA"},{name:"Las Vegas",state:"NV"},{name:"Boston",state:"MA"}]);
	
		cities.insert({name:"Portland",state:"OR"});

		alert(cities({name:"Boston"}).count());

		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
	&lt;/body&gt;
				
&lt;/html&gt;</pre>
				
			<h3>Step 5: Chaining methods</h3>
				<p>You can chain together. Below we will get the first two records from the DB and use the .each() method to alert their names.</p>
				<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;script src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"&gt;&lt;/script&gt;
		&lt;script&gt;

		var cities = TAFFY([{name:"New York",state:"WA"},{name:"Las Vegas",state:"NV"},{name:"Boston",state:"MA"}]);
	
		cities.insert({name:"Portland",state:"OR"});

		cities().limit(2).each(function (r) {alert(r.name)});

		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
	&lt;/body&gt;
				
&lt;/html&gt;</pre>
				
			<h3>Step 6: Updating data</h3>
				<p>You may have noticed that New York is in the wrong state. Let's fix that and alert the new state. </p>
				<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;script src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"&gt;&lt;/script&gt;
		&lt;script&gt;

		var cities = TAFFY([{name:"New York",state:"WA"},{name:"Las Vegas",state:"NV"},{name:"Boston",state:"MA"}]);
	
		cities.insert({name:"Portland",state:"OR"});

		cities({name:"New York"}).update({state:"NY"});

		alert(cities({name:"New York"}).first().state);


		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
	&lt;/body&gt;
				
&lt;/html&gt;</pre>
				
			<h3>Step 7: Sorting</h3>
				<p>Sorting is a big part of TaffyDB using the .order() method.</p>
				<pre>&lt;html&gt;
	&lt;head&gt;
		&lt;script src="https://github.com/typicaljoe/taffydb/raw/master/taffy.js"&gt;&lt;/script&gt;
		&lt;script&gt;

		var cities = TAFFY([{name:"New York",state:"WA"},{name:"Las Vegas",state:"NV"},{name:"Boston",state:"MA"}]);
	
		cities.insert({name:"Portland",state:"OR"});

		alert(cities().order("name").first().name);

		&lt;/script&gt;
	&lt;/head&gt;
	&lt;body&gt;
	&lt;/body&gt;
				
&lt;/html&gt;</pre>
			<h3>What's next</h3>
				<p>There are a lot of other methods you can use against your data. Some highlights include .remove() to delete records, .get() to get an array of records, and .supplant to merge records with a string template. Continue to browse the docs for more ways to use TaffyDB.</p>
				
		


          </div>
           <footer>
         


    </footer>


        </div><!--/span-->
      </div><!--/row-->

      <hr>

      <footer>
        <div align="center"><img src="./index_files/taffydbboxV3.jpg"></div>
      </footer>

    </div><!--/.fluid-container-->

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="./index_files/jquery.js.download"></script>
    <script src="./index_files/bootstrap-transition.js.download"></script>
    <script src="./index_files/bootstrap-alert.js.download"></script>
    <script src="./index_files/bootstrap-modal.js.download"></script>

    <script src="./index_files/bootstrap-dropdown.js.download"></script>
    <script src="./index_files/bootstrap-scrollspy.js.download"></script>
    <script src="./index_files/bootstrap-tab.js.download"></script>
    <script src="./index_files/bootstrap-tooltip.js.download"></script>
    <script src="./index_files/bootstrap-popover.js.download"></script>
    <script src="./index_files/bootstrap-button.js.download"></script>

    <script src="./index_files/bootstrap-collapse.js.download"></script>
    <script src="./index_files/bootstrap-carousel.js.download"></script>
    <script src="./index_files/bootstrap-typeahead.js.download"></script>

  

<iframe id="rufous-sandbox" scrolling="no" frameborder="0" allowtransparency="true" allowfullscreen="true" style="position: absolute; visibility: hidden; display: none; width: 0px; height: 0px; padding: 0px; border: none;" title="Twitter analytics iframe" src="./index_files/saved_resource(1).html"></iframe></body></html>
